<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css"  href="/elementUI/theme-chalk/index.css">
</head>
<body>
<div id="app"  >
    <template>
        <el-form  ref="form" :model="workTemplate"  label-width="90px" style="width: 310px">

            <el-form-item label="模板编号">
                <el-input v-model="workTemplate.number"></el-input>
            </el-form-item>

            <el-form-item label="模板名称">
                <el-input v-model="workTemplate.content"></el-input>
            </el-form-item>

            <el-form-item label="模板类型">
                <el-select filterable  v-model="workTemplate.templateType" placeholder="请选择活动区域">
                    <el-option v-for="item in templateTypes"
                               :label="item.value"
                               :value="item.key"></el-option>
                </el-select>
            </el-form-item>

            <el-form-item label="起草人">
                <el-input disabled v-model="user.name"></el-input>
            </el-form-item>

            <el-form-item label="创建时间">
                <el-date-picker disabled v-model="workTemplate.inputTime" type="date"></el-date-picker>
            </el-form-item>

            <el-form-item label="版本号">
                <el-input disabled v-model="workTemplate.version"></el-input>
            </el-form-item>

            <el-form-item label="备注">
                <el-input type="textarea" v-model="workTemplate.remark"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="onSubmit">创建</el-button>
                <el-button>取消</el-button>
            </el-form-item>
        </el-form>
    </template>
</div>
</body>
<script src="/vue/vue.js"></script>
<script src="/elementUI/index.js"></script>
<script src="/vue/axios.js"></script>
<script>

    const app = new Vue({
        el: '#app',
        data:{
            workTemplate: {
                id:'',
                reviewerId:'',
                reviewer:null,
                drafterId:'',
                drafter:null,
                name:'',
                content:'',
                number:'',
                version:'0.0.1',
                inputTime:new Date(),
                updateTime:'',
                templateType:'',
                templateTypeName:'',
                enable:'',
                remark:''
            },
            templateTypes: [],
            user: {
                name:'',
                id:''
            }
        },
        methods: {
            onSubmit() {
                axios.post(
                    '/work-template/uploadNewTemplate',
                     this.workTemplate
                ).then(res => { if (res.data == 0){
                    alert("创建成功");
                    window.opener=null;
                    window.open('','_self');
                    window.close();
                }} )
            }
        },
        created(){
            axios.get(
                '/work-template/getTemplateTypes',
            ).then(res => { this.templateTypes = res.data; } )
            axios.get(
                '/getUser',
            ).then(res => {
                this.user.name = res.data.name;
                this.user.id = res.data.id;
                this.workTemplate.drafterId = res.data.id;
            } )
        }

    })

</script>
</html>